<?php
class News_model extends CI_Model{
	function __construct(){
		$this->load->database();
	}
	
	function get_news($id=false){
		if($id===false){
			$query=$this->db->get('news');
			return $query->result_array();
		}
		$query=$this->db->get_where('news', array('id' => $id));
		return $query->result_array();
	}
	
	function add_news(){
		
		$data=array(
			'title'=>$this->input->post('title'),
			'slug'=>url_title($this->input->post('title'),'dash',TRUE),
			'text'=>$this->input->post('text'),
			'add_time'=>date('Y-m-d H:i:s',time())
		);
		return $this->db->insert('news',$data);
	}
	
	function edit_news(){
		$data=array(
			'title'=>$this->input->post('title'),
			'text'=>$this->input->post('text')
		);
		return $this->db->update('news',$data,array('id'=>$this->input->post('id')));
	}
	
	function delete_news(){
		return $this->db->delete('news',array('id'=>$this->input->post('id')));
	}
}
